<?php
class Manage_IndexController extends Zendvn_Controller_Action{
	
	public  function init(){
		
		$this->createTemplate(APPLICATION_PATH . '/templates/dashboard','template.ini','template');
	}
	
	public function indexAction(){
		
		$storage = new Zend_Auth_Storage_Session();
		$data = $storage->read();
		
		$shop = new Shop_Model_Index();
		
		$arr = array(
			"userid"=>$data->id,
		);		
		$list_shop = $shop->listItem($arr);
				
		$this->view->list_shop = $list_shop;
		
	}
	
	public function updatepaymentAction(){
		
		if($this->getRequest()->isPost()){

			$idorders = @$_POST["idorders"];
			$payment = @$_POST["payment"];
			$order = new Shop_Model_Order();
			
			if($idorders != "" && $payment != ""){
				$arr = array(
					"id"=>$idorders,
					"payment_method"=>$payment,
				);							
				$order->updateOrder($arr);
			}
			
		}
		
	}
	
	public function updatestatusAction(){
		
		if($this->getRequest()->isPost()){

			$idorders = @$_POST["idorders"];
			$status = @$_POST["status"];
			$order = new Shop_Model_Order();
			$order_history = new Shop_Model_OrderHistory();
			
			if($idorders != "" && $status != ""){
				$arr = array(
					"id"=>$idorders,
					"status"=>$status,
				);							
				$order->updateOrder($arr);
				
				//insert orders_history
				$arr = array(
					"ordersid"=>$idorders,
					"status"=>$status,
					"note"=>"",
				);
				$order_history->insertOrderHistory($arr);
			}
			
		}
		
	}
	
}